﻿using System.IO;
using System.Reflection;

namespace Tab2Sql
{
    /// <summary>
    /// A class for accessing Assembly details, etc. 
    /// </summary>
    public class Assemblage
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/>
        /// </returns>
        public static string AssemblyVersionString()
        {
           return  Assembly.GetExecutingAssembly().GetName().Version.ToString(); 
        }


        #region Assembly Attribute Accessors

        /// <summary>
        /// Title in current assembly.
        /// </summary>
        public string AssemblyTitle
        {
            get
            {
                object[] attributes =
                    Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyTitleAttribute), false);
                if (attributes.Length > 0)
                {
                    var titleAttribute = (AssemblyTitleAttribute) attributes[0];
                    if (titleAttribute.Title != "")
                    {
                        return titleAttribute.Title;
                    }
                }
                return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            }
        }

        /// <summary>
        /// Version in current assembly.
        /// </summary>
        public string AssemblyVersion
        {
            get { return Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
        }

        /// <summary>
        /// Description of product in current assembly.
        /// </summary>
        public string AssemblyDescription
        {
            get
            {
                object[] attributes =
                    Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyDescriptionAttribute) attributes[0]).Description;
            }
        }

        /// <summary>
        /// Product in current assembly.
        /// </summary>
        public string AssemblyProduct
        {
            get
            {
                object[] attributes =
                    Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyProductAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyProductAttribute) attributes[0]).Product;
            }
        }

        /// <summary>
        /// Copyright in current assembly.
        /// </summary>
        public string AssemblyCopyright
        {
            get
            {
                object[] attributes =
                    Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCopyrightAttribute) attributes[0]).Copyright;
            }
        }

        /// <summary>
        /// Company/author in current assembly.
        /// </summary>
        public string AssemblyCompany
        {
            get
            {
                object[] attributes =
                    Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyCompanyAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCompanyAttribute) attributes[0]).Company;
            }
        }

        #endregion
        /// <summary>
        ///
        /// </summary>
        public string FullName
        {
            get { return Assembly.GetCallingAssembly ().FullName; }
        }
        /// <summary>
        ///
        /// </summary>
        public string Location
        {
            get { return Assembly.GetCallingAssembly ().Location; }
        }
        /// <summary>
        ///
        /// </summary>
        public long HostContext
        {
            get { return Assembly.GetCallingAssembly().HostContext; }
        }
    }
}